package com.yy;



import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.tio.websocket.starter.EnableTioWebSocketServer;

import com.alibaba.fastjson.serializer.SerializerFeature;
import com.alibaba.fastjson.support.config.FastJsonConfig;
import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;

@EnableScheduling // 开启对计划任务的支持
@SpringBootApplication(exclude= {DataSourceAutoConfiguration.class})
@EnableTransactionManagement//开启事物
@EnableTioWebSocketServer
public class YyApplication {

	public static void main(String[] args) {
		SpringApplication.run(YyApplication.class, args);
	}
	//JSON全局配置
    @Bean
    public HttpMessageConverters fastJsonHttpMessageConverters() {
        // 初始化转换器
        FastJsonHttpMessageConverter fastConvert = new FastJsonHttpMessageConverter();
        // 初始化一个转换器配置
        FastJsonConfig fastJsonConfig = new FastJsonConfig();
        //禁止循环引用DisableCircularReferenceDetect
        fastJsonConfig.setSerializerFeatures(SerializerFeature.PrettyFormat, SerializerFeature.WriteDateUseDateFormat,SerializerFeature.WriteMapNullValue,
                SerializerFeature.WriteNullNumberAsZero,SerializerFeature.WriteNullListAsEmpty,SerializerFeature.WriteNullStringAsEmpty,SerializerFeature.WriteNullBooleanAsFalse,SerializerFeature.DisableCircularReferenceDetect);
        //3、中文乱码解决方案
      //  List<MediaType> fastMedisTypes = new ArrayList<MediaType>();
        //fastMedisTypes.add(MediaType.APPLICATION_JSON_UTF8);//设定Json格式且编码为utf-8
       // fastConvert.setSupportedMediaTypes(fastMedisTypes);
        //4、将转换规则应用于转换对象
        fastConvert.setFastJsonConfig(fastJsonConfig);
        // 将配置设置给转换器并添加到HttpMessageConverter转换器列表中
        fastConvert.setFastJsonConfig(fastJsonConfig);
        return new HttpMessageConverters(fastConvert);
    }
}
